
********************************************************************************
*Table A8; Column 1 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_blacks, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54




preserve
gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3

global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

reg newbw2500 $treat_var $state_var i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms, cluster(mom_birth_state)

local Z=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
lincom (_b[Post0]*meanPost0/`Z')+(_b[Post1]*meanPost1/`Z')+(_b[Post2]*meanPost2/`Z')+(_b[Post3]*meanPost3/`Z')+(_b[Post4]*meanPost4/`Z')
restore

********************************************************************************

set seed 23260513
capture postclose placebo		  
postfile placebo b using "$data/table_a8_c1", replace
forvalues i=1/500 {
use $data/estimation_sample_blacks, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54



preserve
bsample, cluster(mom_birth_state)

gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3


global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
qui reg newbw2500 $treat_var $state_var i.age_cat  i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms
local V=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
local c_weighted=(_b[Post0]*meanPost0/`V')+(_b[Post1]*meanPost1/`V')+(_b[Post2]*meanPost2/`V')+(_b[Post3]*meanPost3/`V')+(_b[Post4]*meanPost4/`V')
post placebo (`c_weighted')
restore
}

postclose placebo

use table_a8_c1, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/



********************************************************************************
*Table A8; Column 2 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_blacks, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54




preserve
gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3

global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

reg newpretermLT37 $treat_var $state_var i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms, cluster(mom_birth_state)

local Z=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
lincom (_b[Post0]*meanPost0/`Z')+(_b[Post1]*meanPost1/`Z')+(_b[Post2]*meanPost2/`Z')+(_b[Post3]*meanPost3/`Z')+(_b[Post4]*meanPost4/`Z')
restore

********************************************************************************

set seed 23260513
capture postclose placebo		  
postfile placebo b using "$data/table_a8_c2", replace
forvalues i=1/500 {
use $data/estimation_sample_blacks, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54



preserve
bsample, cluster(mom_birth_state)

gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3


global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
qui reg newpretermLT37 $treat_var $state_var i.age_cat  i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms
local V=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
local c_weighted=(_b[Post0]*meanPost0/`V')+(_b[Post1]*meanPost1/`V')+(_b[Post2]*meanPost2/`V')+(_b[Post3]*meanPost3/`V')+(_b[Post4]*meanPost4/`V')
post placebo (`c_weighted')
restore
}

postclose placebo

use table_a8_c2, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/


********************************************************************************
*Table A8; Column 3 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_whites, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54




preserve
gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3

global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

reg newbw2500 $treat_var $state_var i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms, cluster(mom_birth_state)

local Z=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
lincom (_b[Post0]*meanPost0/`Z')+(_b[Post1]*meanPost1/`Z')+(_b[Post2]*meanPost2/`Z')+(_b[Post3]*meanPost3/`Z')+(_b[Post4]*meanPost4/`Z')
restore

********************************************************************************

set seed 23260513
capture postclose placebo		  
postfile placebo b using "$data/table_a8_c3", replace
forvalues i=1/500 {
use $data/estimation_sample_whites, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54



preserve
bsample, cluster(mom_birth_state)

gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3


global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
qui reg newbw2500 $treat_var $state_var i.age_cat  i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms
local V=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
local c_weighted=(_b[Post0]*meanPost0/`V')+(_b[Post1]*meanPost1/`V')+(_b[Post2]*meanPost2/`V')+(_b[Post3]*meanPost3/`V')+(_b[Post4]*meanPost4/`V')
post placebo (`c_weighted')
restore
}

postclose placebo

use table_a8_c3, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/



********************************************************************************
*Table A8; Column 4 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_whites, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54




preserve
gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3

global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

reg newpretermLT37 $treat_var $state_var i.age_cat i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms, cluster(mom_birth_state)

local Z=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
lincom (_b[Post0]*meanPost0/`Z')+(_b[Post1]*meanPost1/`Z')+(_b[Post2]*meanPost2/`Z')+(_b[Post3]*meanPost3/`Z')+(_b[Post4]*meanPost4/`Z')
restore

********************************************************************************

set seed 23260513
capture postclose placebo		  
postfile placebo b using "$data/table_a8_c4", replace
forvalues i=1/500 {
use $data/estimation_sample_whites, clear

*drop NM, which implemented only Science reform. 
drop if mom_birth_state==35

gen math_diff=.
replace math_diff=1 if mom_birth_state==2
replace math_diff=1 if mom_birth_state==1
replace math_diff=2 if mom_birth_state==5
replace math_diff=1 if mom_birth_state==4
replace math_diff=2 if mom_birth_state==6
replace math_diff=3 if mom_birth_state==9
replace math_diff=1 if mom_birth_state==11
replace math_diff=1 if mom_birth_state==10
replace math_diff=3 if mom_birth_state==12
replace math_diff=1 if mom_birth_state==13
replace math_diff=1 if mom_birth_state==16
replace math_diff=2 if mom_birth_state==17
replace math_diff=1 if mom_birth_state==18
replace math_diff=1 if mom_birth_state==20
replace math_diff=1 if mom_birth_state==21
replace math_diff=1 if mom_birth_state==22
replace math_diff=1 if mom_birth_state==24
replace math_diff=2 if mom_birth_state==23
replace math_diff=1 if mom_birth_state==29
replace math_diff=1 if mom_birth_state==28
replace math_diff=1 if mom_birth_state==37
replace math_diff=1 if mom_birth_state==38
replace math_diff=1 if mom_birth_state==33
replace math_diff=1 if mom_birth_state==32
replace math_diff=1 if mom_birth_state==39
replace math_diff=1 if mom_birth_state==40
replace math_diff=1 if mom_birth_state==41
replace math_diff=2 if mom_birth_state==42
replace math_diff=1 if mom_birth_state==44
replace math_diff=1 if mom_birth_state==45
replace math_diff=1 if mom_birth_state==46
replace math_diff=1 if mom_birth_state==47
replace math_diff=1 if mom_birth_state==48
replace math_diff=1 if mom_birth_state==49
replace math_diff=1 if mom_birth_state==51
replace math_diff=2 if mom_birth_state==50
replace math_diff=2 if mom_birth_state==53
replace math_diff=2 if mom_birth_state==55
replace math_diff=1 if mom_birth_state==54



preserve
bsample, cluster(mom_birth_state)

gen Post0=0
replace Post0=1 if index==0& math_diff==1
replace Post0=2 if index==0& math_diff==2
replace Post0=3 if index==0& math_diff==3

gen Post1=0
replace Post1=1 if index==1&math_diff==1
replace Post1=2 if index==1&math_diff==2
replace Post1=3 if index==1&math_diff==3

gen Post2=0
replace Post2=1 if index==2&math_diff==1
replace Post2=2 if index==2&math_diff==2
replace Post2=3 if index==2&math_diff==3

gen Post3=0
replace Post3=1 if index==3&math_diff==1
replace Post3=2 if index==3&math_diff==2
replace Post3=3 if index==3&math_diff==3

gen Post4=0
replace Post4=1 if index>=4&math_diff==1
replace Post4=2 if index>=4&math_diff==2
replace Post4=3 if index>=4&math_diff==3


global treat_var "Post0 Post1 Post2 Post3 Post4"
global state_var "Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}
qui reg newpretermLT37 $treat_var $state_var i.age_cat  i.tbo i.male i.year i.birth_month i.division#c.by i.by i.mom_birth_state other_reforms
local V=meanPost0+meanPost1+meanPost2+meanPost3+meanPost4
local c_weighted=(_b[Post0]*meanPost0/`V')+(_b[Post1]*meanPost1/`V')+(_b[Post2]*meanPost2/`V')+(_b[Post3]*meanPost3/`V')+(_b[Post4]*meanPost4/`V')
post placebo (`c_weighted')
restore
}

postclose placebo

use table_a8_c4, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/

